package com.zhiyou100.advie;

import com.zhiyou100.entity.Student;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * 通知类
 *
 * @author yang
 * @className MyAdvice
 * @packageName com.zhiyou100.advice
 * @Description TODO 通知类
 * @date 2020-08-20 09:20
 */

// 注册 bean
@Component("myAdvice2")
// 指定此类是 通知类
@Aspect
public class MyAdvice extends Student {
    @After("execution(* com.zhiyou100.entity.*.*(..))")
    public void afterMethod1() {
        System.out.println("public void afterMethod1 11111");
    }

    @AfterReturning("execution(* com.zhiyou100.entity.*.*(..))")
    public void afterMethod2() {
        System.out.println("public void afterMethod2 222222");
    }

    @Before("execution(* com.zhiyou100.entity.*.*(..))")
    public void beforeMethod1() {
        System.out.println("public void beforeMethod1 0000000000");
    }

    @Around("execution(* com.zhiyou100.entity.*.*(..))")
    public Object aroundMethod(ProceedingJoinPoint joinPoint) {
        System.out.println(" public Object aroundMethod 前");
        Object obj = null;
        try {
            obj = joinPoint.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        System.out.println(" public Object aroundMethod 后");
        return obj;
    }

    @AfterThrowing(value = "execution(* com.zhiyou100.entity.*.*(..))", throwing = "e")
    public void throwsMethod(Exception e) {
        System.out.println("public void throwsMethod 出现异常了！！！原因是 ：：：" + e.getMessage());
    }
}
